#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_energy_field.info <<'%EOF%'
   cc_energy_field
   ---------------
   Molecule:         HF in C2v
   Wave Function:    CCSD, CCSD(T) / aug-cc-pVDZ
   Test Purpose:     Finite field for energy and binary packing of
                     two-electron integrals
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_energy_field.mol <<'%EOF%'
BASIS
aug-cc-pVDZ
Quadrupole convergence calculations
for HF in CM coor. system
    2    2  X  Y  Z   1.00D-15
        1.0   1
H     0.0000000000000000  0.000000000000000   1.645584440000000       *
        9.0   1
F     0.0000000000000000  0.000000000000000   -.08729478000000        *
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_energy_field.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.THETA
**WAVE FUNCTION
.CC
*HAMILTONIAN
.FIELD
 2.0D-05
ZZTHETA
*SCF INP
.THRESH
 5.0D-10
.DOUBLY OCCUPIED
 3 1 1 0
*CC INP
.PACK
1.0D-14
.CCSD
.CC(T)
.PRINT
 6
.THRENR
5.0D-10
.FROIMP
1 0 0 0
0 0 0 0
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_energy_field.check
cat >>cc_energy_field.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Final * HF energy: * -100\.0334452377" $log | wc -l`
CRIT2=`$GREP "Total MP2   energy: * -100\.255716276" $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy:  * -100\.259424988" $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRL[1]=5
ERROR[1]="ENERGIES NOT CORRECT"


# Triples corrections
CRIT1=`$GREP  " The E4 doubles and triples: * ( -|-0)\.004724965" $log | wc -l`
CRIT2=`$GREP  " The E5 singles and triples: * ( |0)\.000585648" $log | wc -l`
CRIT3=`$GREP  " Total energy CCSD\(T\): * -100\.263564306" $log | wc -l`
CRIT4=`$GREP  "Ecorr = * -100\.26356430599" $log | wc -l`

TEST[2]=`expr $CRIT1  \+ $CRIT2  \+ $CRIT3  \+ $CRIT4`

CTRL[2]=7
ERROR[2]="TRIPLES CORRECTIONS NOT CORRECT"


PASSED=1
for i in 1 2
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
